var getLocation = function (successFunc, errorFunc) { //successFunc获取定位成功回调函数，errorFunc获取定位失败回调  
    if (navigator.geolocation) {  
        navigator.geolocation.getCurrentPosition(function (position) {  
            var lat = position.coords.latitude;  
            var lon = position.coords.longitude;  
//            alert(lat+":"+lon);
            var point = new BMap.Point(lon, lat); // 创建点坐标  
            var gc = new BMap.Geocoder();  
            gc.getLocation(point, function (rs) {  
                var addComp = rs.addressComponents;  
                if (successFunc != undefined)  
                    successFunc(addComp);  
            });  
        },  
        function (error) {  
            switch (error.code) {  
                case 1:  
                    alert("位置服务被拒绝。");  
                    break;  
                case 2:  
                    alert("暂时获取不到位置信息。");  
                    break;  
                case 3:  
                    alert("获取位置信息超时。");  
                    break;  
                default:  
                    alert("未知错误。");  
                    break;  
            }  
            if (errorFunc != undefined)  
                errorFunc(error);  
        }, { timeout: 5000, enableHighAccuracy: true });  
    } else {  
        alert("你的浏览器不支持获取地理位置信息。");  
        if (errorFunc != undefined)  
            errorFunc("你的浏览器不支持获取地理位置信息。");  
    }  
};  
var showPositionError = function (error) {  
    switch (error.code) {  
        case 1:  
            alert("位置服务被拒绝。");  
            break;  
        case 2:  
            alert("暂时获取不到位置信息。");  
            break;  
        case 3:  
            alert("获取位置信息超时。");  
            break;  
        default:  
            alert("未知错误。");  
            break;  
    }  
}; 
/**
 * 取终端定位地址
 */
function getAddress(callback){
	var clientAddress=localStorage.getItem("client_address")||"{}";
	clientAddress=JSON.parse(clientAddress);
	//取到存储的地址,如果没有则实时取
	if(!clientAddress.province || !clientAddress.city){
		getLocation(function(addr){
			localStorage.setItem("client_address", JSON.stringify(addr));
			callback(addr);
		},function(error){
			showPositionError(error);
			localStorage.setItem("client_address", JSON.stringify(remote_ip_info));
			callback(remote_ip_info);
		});
	}else{
		callback(clientAddress);
	}
}
